﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace killsm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OSType osType = GetOSType();
            string command;
            if (osType == OSType.WindowsVista || osType == OSType.Windows7)
            {
                //taskkill /pid [PID] taskkill /?
                command = "taskkill /im " + label2.Text;
            }
            else
            {
                //ntsd -c q -p pid
                command = "ntsd -c q -pn " + label2.Text;
            }
            Process pro = new Process();
            pro.StartInfo.FileName = "cmd.exe";
            //pro.StartInfo.Arguments = arguments;
            pro.StartInfo.UseShellExecute = false;
            pro.StartInfo.RedirectStandardInput = true;
            pro.StartInfo.RedirectStandardOutput = true;
            pro.StartInfo.RedirectStandardError = true;
            pro.StartInfo.CreateNoWindow = true;
            pro.Start();
            pro.StandardInput.WriteLine(command); 
            pro.StandardInput.WriteLine("exit");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FrmSelect frm = new FrmSelect();
            frm.ShowDialog();
            label2.Text = frm.ProcessName;
        }

        public OSType GetOSType()
        {
            Version ver = System.Environment.OSVersion.Version;
            OSType type;
            if (ver.Major == 5 && ver.Minor == 0)
            {
                type = OSType.Windows2000;
            }
            else if (ver.Major == 5 && ver.Minor == 1)
            {
                type = OSType.WindowsXP;
            }
            else if (ver.Major == 5 && ver.Minor == 2)
            {
                type = OSType.Windows2003;
            }
            else if (ver.Major == 6 && ver.Minor == 0)
            {
                type = OSType.WindowsVista;
            }
            else if (ver.Major == 6 && ver.Minor == 1)
            {
                type = OSType.Windows7;
            }
            else
            {
                type = OSType.Other;
            }
            return type;
        }
    }
    public enum OSType
    {
        Windows2000,
        WindowsXP,
        Windows2003,
        WindowsVista,
        Windows7,
        Other
    }
}
